2ac8fd
@@ -166,7 +166,7 @@
public int getNanos() {
       return timestamp.getNanos();
     }
 
-    return TimestampWritable.getNanos(currentBytes, offset+4);
+    return hasDecimal() ? TimestampWritable.getNanos(currentBytes, offset+4) : 0;
   }
 
   /**
@@ -183,7 +183,7 @@
private int getTotalLength() {
    */
   private int getDecimalLength() {
     checkBytes();
-    return WritableUtils.decodeVIntSize(currentBytes[offset+4]);
+    return hasDecimal() ? WritableUtils.decodeVIntSize(currentBytes[offset+4]) : 0;
   }
 
   public Timestamp getTimestamp() {
@@ -393,7 +393,7 @@
public static void convertTimestampToBytes(Timestamp t, byte[] b,
     long millis = t.getTime();
     int nanos = t.getNanos();
 
-    boolean hasDecimal = setNanosBytes(nanos, b, offset+4);
+    boolean hasDecimal = nanos != 0 && setNanosBytes(nanos, b, offset+4);
     setSecondsBytes(millis, b, offset, hasDecimal);
   }
 
@@ -471,8 +471,11 @@
public static Timestamp doubleToTimestamp(double f) {
   }
 
   public static void setTimestamp(Timestamp t, byte[] bytes, int offset) {
+    boolean hasDecimal = hasDecimal(bytes[offset]);
     t.setTime(((long) TimestampWritable.getSeconds(bytes, offset)) * 1000);
-    t.setNanos(TimestampWritable.getNanos(bytes, offset+4));
+    if (hasDecimal) {
+      t.setNanos(TimestampWritable.getNanos(bytes, offset+4));
+    }
   }
 
   public static Timestamp createTimestamp(byte[] bytes, int offset) {
@@ -481,6 +484,10 @@
public static Timestamp createTimestamp(byte[] bytes, int offset) {
     return t;
   }
 
+  public boolean hasDecimal() {
+    return hasDecimal(currentBytes[offset]);
+  }
+
   /**
    *
    * @param b first byte in an encoded TimestampWritable
